package com.example.a33mvvm.live;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseViewModel;
import com.example.base_mvvm.base.view.GiftEntity;
import com.example.base_mvvm.entity.FollowEntity;
import com.example.base_mvvm.money.Money;
import com.example.base_mvvm.net.Const;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class LiveViewModel extends BaseViewModel<LiveRepo> {
    public MutableLiveData<FollowEntity> follow_success = new MutableLiveData<>();
    public MutableLiveData<String> follow_failure = new MutableLiveData<>();
    public MutableLiveData<FollowEntity> noFollow_success = new MutableLiveData<>();
    public MutableLiveData<String> noFollow_failure = new MutableLiveData<>();
    public MutableLiveData<GiftEntity> gift_success = new MutableLiveData<>();
    public MutableLiveData<String> gift_failure = new MutableLiveData<>();
    public MutableLiveData<Money> m_success = new MutableLiveData<>();
    public MutableLiveData<String> um_failure = new MutableLiveData<>();
    public LiveViewModel(@NonNull Application application) {
        super(application);
    }
    public void follow(String auth_name){
        HashMap<String, Object> map = new HashMap<>();
        map.put(Const.AUTH_NAME,auth_name);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.follow(body,follow_success,follow_failure);
    }
    public void noFollow(String auth_name){
        HashMap<String, Object> map = new HashMap<>();
        map.put(Const.AUTH_NAME,auth_name);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.noFollow(body,noFollow_success,noFollow_failure);
    }


    public void getMoney(String username){
        repo.getMoney(username,m_success,um_failure);
    }
    public void updateMoney(Money money){
        repo.updateMoney(money);
    }
    public void gift(){
        repo.getGift(gift_success,gift_failure);
    }
    @Override
    protected LiveRepo createRepo() {

        return new LiveRepo();
    }
}
